package com.central.scheduler.plugin.task.datax.json.writer;

import com.central.common.entity.WriterParams;
import com.central.common.enums.WriteMode;
import com.central.common.model.DatasourceInfo;
import com.central.scheduler.plugin.task.datax.json.WriterJson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Tindy
 * @date 2022/3/10
 * @describe
 */
public class MysqlWriterJson implements WriterJson {
    private List<String> column;
    private List<Map<String,Object>> connection=new ArrayList<>();
    private String username;
    private String password;
    private String table;
    private WriteMode writeMode;

    public MysqlWriterJson(WriterParams writer, DatasourceInfo writerDatasource) {
        this.column=writer.getColumn().stream().map(x->x.get("name")).collect(Collectors.toList());
        this.table=writer.getTbName();
        this.writeMode=writer.getWriteMode();
        this.username=writerDatasource.getUsername();
        this.password=writerDatasource.getPassword();
        HashMap<String, Object> connMap = new HashMap<>();
        String jdbcUrl="jdbc:mysql://"+writerDatasource.getHost()+":"+writerDatasource.getPort()+"/"+writer.getDbName();
        connMap.put("jdbcUrl",jdbcUrl);
        ArrayList<String> tables = new ArrayList<>();
        tables.add(writer.getTbName());
        connMap.put("table",tables);
        this.connection.add(connMap);
    }
}
